clear all; addpath('auxiliar'); addpath('Simulated_Datasets');load events;
%% EVENT ANALYSIS LEAD UP TO DEFAULT

DE_line_private=[mean(bSIM_Defaultedm5_DE),mean(bSIM_Defaultedm4_DE),mean(bSIM_Defaultedm3_DE),mean(bSIM_Defaultedm2_DE),mean(bSIM_Defaultedm1_DE),mean(bSIM_Defaulted_DE)];
DE_line_public=[mean(BGSIM_Defaultedm5_DE),mean(BGSIM_Defaultedm4_DE),mean(BGSIM_Defaultedm3_DE),mean(BGSIM_Defaultedm2_DE),mean(BGSIM_Defaultedm1_DE),mean(BGSIM_Defaulted_DE)];
SP_line_private=[mean(bSIM_Defaultedm5_SP),mean(bSIM_Defaultedm4_SP),mean(bSIM_Defaultedm3_SP),mean(bSIM_Defaultedm2_SP),mean(bSIM_Defaultedm1_SP),mean(bSIM_Defaulted_SP)];
SP_line_public=[mean(BGSIM_Defaultedm5_SP),mean(BGSIM_Defaultedm4_SP),mean(BGSIM_Defaultedm3_SP),mean(BGSIM_Defaultedm2_SP),mean(BGSIM_Defaultedm1_SP),mean(BGSIM_Defaulted_SP)];
xevent={'D-5','D-4','D-3','D-2','D-1','Default'};
c0 = categorical(xevent);
c2=reordercats(c0,{'D-5','D-4','D-3','D-2','D-1','Default'});

      figure
plot(c2,DE_line_private,'Linewidth',1,'Color','r','LineStyle',':','Marker','o','MarkerFaceColor','r'); hold on;
plot(c2,SP_line_private,'Linewidth',1,'Color','b','LineStyle',':','Marker','o','MarkerFaceColor','b'); hold on;
plot(c2,DE_line_public,'Linewidth',0.1,'Color','r','LineStyle','-','Marker','+');hold on;legend boxoff;
plot(c2,SP_line_public,'Linewidth',0.1,'Color','b','LineStyle','-','Marker','+');hold on;legend boxoff;



ylim([0.1, .5]);
ylabel('Debt in percent of mean output','Interpreter','Latex'); legend boxoff;
xlabel('Years before a default','Interpreter','Latex')
Hlegend=legend('Private debt baseline','Private debt planner','Public debt baseline','Public debt planner','Location','northeast'); set(Hlegend,'Interpreter','Latex')
hold off;%xlim([-5 0]);
exportfig(gcf,'Plots\Fig9A_EventDefault.eps','color','cmyk','resolution',1600)

%% EVENT ANALYSIS REENTRY

DE_line_private=[mean(bSSm3_DE),mean(bSSm2_DE),mean(bSSm1_DE),mean(bSS_DE),mean(bSSp1_DE),mean(bSSp2_DE),mean(bSSp3_DE)];
DE_line_public=[mean(BGSSm3_DE),mean(BGSSm2_DE),mean(BGSSm1_DE),mean(BGSS_DE),mean(BGSSp1_DE),mean(BGSSp2_DE),mean(BGSSp3_DE)];
SP_line_private=[mean(bSSm3_SP),mean(bSSm2_SP),mean(bSSm1_SP),mean(bSS_SP),mean(bSSp1_SP),mean(bSSp2_SP),mean(bSSp3_SP)];
SP_line_public=[mean(BGSSm3_SP),mean(BGSSm2_SP),mean(BGSSm1_SP),mean(BGSS_SP),mean(BGSSp1_SP),mean(BGSSp2_SP),mean(BGSSp3_SP)];
%xevent={'Reentry','R+1','R+2','R+3','R+4','R+5','R+6'};

xevent={'FC-3','FC-2','FC-1','Fin. Crisis','FC+1','FC+2','FC+3'};

c0 = categorical(xevent);
c2=reordercats(c0,{'FC-3','FC-2','FC-1','Fin. Crisis','FC+1','FC+2','FC+3'});

      figure
plot(c2,DE_line_private,'Linewidth',1,'Color','r','LineStyle',':','Marker','o','MarkerFaceColor','r'); hold on;
plot(c2,SP_line_private,'Linewidth',1,'Color','b','LineStyle',':','Marker','o','MarkerFaceColor','b'); hold on;
plot(c2,DE_line_public,'Linewidth',0.5,'Color','r','LineStyle','-','Marker','+');hold on;legend boxoff;
plot(c2,SP_line_public,'Linewidth',0.5,'Color','b','LineStyle','-','Marker','+');hold on;legend boxoff;



ylim([0, .5]);
ylabel('Debt in percent of mean output','Interpreter','Latex'); legend boxoff;
%xlabel('Years after reentry','Interpreter','Latex')
Hlegend=legend('Private debt baseline','Private debt planner','Public debt baseline','Public debt planner','Location','southeast','Interpreter','Latex'); set(Hlegend,'Interpreter','Latex')
hold off;%xlim([-5 0]);
exportfig(gcf,'Plots\Fig9B_EventReentry.eps','color','cmyk','resolution',1600)

